package com.hsjk.szwj.module.official.controller.admin.unit;

import com.hsjk.szwj.framework.common.pojo.CommonResult;
import com.hsjk.szwj.framework.common.pojo.PageResult;
import com.hsjk.szwj.module.official.controller.admin.unit.vo.AdminModuleBannerCreateReqVO;
import com.hsjk.szwj.module.official.controller.admin.unit.vo.AdminModuleBannerDetailRespVO;
import com.hsjk.szwj.module.official.controller.admin.unit.vo.AdminModuleBannerPageReqVO;
import com.hsjk.szwj.module.official.controller.admin.unit.vo.AdminModuleBannerPageRespVO;
import com.hsjk.szwj.module.official.controller.admin.unit.vo.AdminModuleBannerUpdateReqVO;
import com.hsjk.szwj.module.official.service.unit.IUnitService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

import static com.hsjk.szwj.framework.common.pojo.CommonResult.success;

/**
 * @author chenjiawei
 * @desc 模块化控制器
 * @Date 2023/11/23 22:02
 **/
@Tag(name = "后台管理端 - 官网模块化banner相关接口")
@RestController
@RequestMapping("/official-website/unit/banner")
@Validated
public class AdminUnitBannerController {
    @Resource
    private IUnitService unitService;

    @PostMapping("/create")
    @Operation(summary = "创建banner")
    @PreAuthorize("@ss.hasPermission('official-website:unit:banner:create')")
    public CommonResult<Boolean> createModuleBanner(@RequestBody @Valid AdminModuleBannerCreateReqVO reqVO) {
        return success(unitService.createModuleBanner(reqVO));
    }

    @GetMapping("/get-banner-by-id")
    @Operation(summary = "根据bannerid获取banner详情")
    @PreAuthorize("@ss.hasPermission('official-website:unit:banner:query')")
    public CommonResult<AdminModuleBannerDetailRespVO> getAdminModuleBannerDetail(@RequestParam Long id) {
        return success(unitService.getAdminModuleBannerDetail(id));
    }

    @PostMapping("/update")
    @Operation(summary = "更新banner")
    @PreAuthorize("@ss.hasPermission('official-website:unit:banner:update')")
    public CommonResult<Boolean> updateModuleBanner(@RequestBody @Valid AdminModuleBannerUpdateReqVO reqVO) {
        return success(unitService.updateModuleBanner(reqVO));
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除banner")
    @PreAuthorize("@ss.hasPermission('official-website:unit:banner:delete')")
    public CommonResult<Boolean> deleteModuleBanner(@RequestParam("id") Long id) {
        return success(unitService.deleteModuleBanner(id));
    }

    @PostMapping("/page")
    @Operation(summary = "banner分页查询")
    @PreAuthorize("@ss.hasPermission('official-website:unit:banner:query')")
    public CommonResult<PageResult<AdminModuleBannerPageRespVO>> getAdminModuleBannerPage(@RequestBody @Valid AdminModuleBannerPageReqVO reqVO) {
        return success(unitService.getAdminModuleBannerPage(reqVO));
    }
}
